package 剑指offer_leetcode;

/**
 * JZ64求1234n
 */
public class 剑指Offer64_求1234n {
    //位运算 递归
    public int sumNums(int n) {
        boolean flag = (n > 1) && ((n += sumNums(n-1))>0);
        return n;
    }

    /**
     * 等差数列的前n项和：
     * Sn=[n(A1+An)]/2
     * Sn=nA1+[n(n-1)d]/2
     */
    public int sumNums2(int n) {
        int sum = 0;
        sum = (int) (n + Math.pow(n,2)) >> 1;
        return  sum;
    }

}
